package contents.entities;

import java.util.List;
import java.util.Comparator;
import java.text.ParseException;

public class TutoragesForTutorage {
    public static class ByDateComparator implements Comparator {
        public int compare(Object object1, Object object2) {
            Tutorage tutorage1 = ((TutoragesForTutorage) object1).getMyTutorage();
            Tutorage tutorage2 = ((TutoragesForTutorage) object2).getMyTutorage();
            
            java.text.SimpleDateFormat datetimeFormat = new java.text.SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
            try {
                java.util.Date date1 = datetimeFormat.parse(tutorage1.getDateString() + " " + tutorage1.getTimeString());
                java.util.Date date2 = datetimeFormat.parse(tutorage2.getDateString() + " " + tutorage2.getTimeString());
                // return negative of result, newer dates go first
                return -date1.compareTo(date2);
            } catch (ParseException exception) {
                // this should never happen
                return 0;
            }
        }   
    }
    
    private Tutorage myTutorage;
    private List<Tutorage> remotePeersTutorages;

    public TutoragesForTutorage(Tutorage myTutorage, List<Tutorage> remotePeersTutorages) {
        this.myTutorage = myTutorage;
        this.remotePeersTutorages = remotePeersTutorages;
    }

    public Tutorage getMyTutorage() {
        return myTutorage;
    }

    public List<Tutorage> getRemotePeersTutorages() {
        return remotePeersTutorages;
    }
}
